package unit04.day01;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;

/**
 * RAF提供了方便读写基本类型数据的方法
 * @author cola
 *
 */
public class RandomAccessFileDemo3 {

	public static void main(String[] args) throws IOException {
		RandomAccessFile file = new RandomAccessFile("abc.dat","rw");
		int max = Integer.MAX_VALUE;
		file.write(max>>>24);
		System.out.println("pos:"+file.getFilePointer());
		file.write(max>>>16);
		file.write(max>>>8);
		file.write(max);
		System.out.println("pos:"+file.getFilePointer());
		file.writeInt(max);
		file.writeLong(1234L);
		System.out.println("pos:"+file.getFilePointer());
		file.writeDouble(123.123);
		System.out.println("pos:"+file.getFilePointer());
		
		//移动指针到指定位置
		file.seek(0);
		System.out.println("pos:"+file.getFilePointer());
		int i = file.readInt();
		System.out.println(i);
		file.seek(8);
		long l = file.readLong();
		System.out.println(l);
		Double d = file.readDouble();
		System.out.println(d);
		file.seek(0);
		long l1 = file.readLong();
		System.out.println(l1);
		
		file.close();
	}

}
